<?php
namespace App\Traits;

use App\Models\FakeList;
use Illuminate\Http\Request;

Trait Trait50_51 {

    public function co2alarm()
    {
        $data = FakeList::select(['extra_data'])->where(['id' => 86])->get();
        $responseJson = [
            'code' => 200,
            'message' => '',
            'data' => $data
        ];
        return response()->json($responseJson);
    }

    public function setAlarm(Request $request)
    {
        $validate = $request->validate(
            [
                'pressure' => 'required',
                'temperature' => 'required',
                'humidity' => 'required'
            ]
        );
        $data = FakeList::where(['id' => 86])->update([
            'extra_data->pressure' => $validate['pressure'],
            'extra_data->temperature' => $validate['temperature'],
            'extra_data->humidity' => $validate['humidity'],
        ]);
        $responseJson = [
            'code' => 200,
            'message' => '',
            'data' => $data
        ];
        return response()->json($responseJson);
    }

}
